﻿using System.IO;
using System.Text;
using System.Web.Mvc;
using System.Web.UI;

namespace PortalCurriculo.MvcWebUI.Helpers
{
    public class HtmlHelper
    {
        

        public static string RenderPartialToString(string controlName, object viewData)
        {
            ViewPage viewPage = new ViewPage() { ViewContext = new ViewContext() };
            //viewPage.Url = GetBogusUrlHelper();

            viewPage.ViewData = new ViewDataDictionary(viewData);
            viewPage.Controls.Add(viewPage.LoadControl(controlName));

            StringBuilder sb = new StringBuilder();
            using (StringWriter sw = new StringWriter(sb))
            {
                using (HtmlTextWriter tw = new HtmlTextWriter(sw))
                {
                    viewPage.RenderControl(tw);
                }
            }

            return sb.ToString();
        }

        //public static UrlHelper GetBogusUrlHelper()
        //{
        //    var httpContext = HttpContext.Current;

        //    if (httpContext == null)
        //    {
        //        var request = new HttpRequest("/", ConfigurationHelper.Config.Url.ToString(), "");
        //        var response = new HttpResponse(new StringWriter());
        //        httpContext = new HttpContext(request, response);
        //    }

        //    var httpContextBase = new HttpContextWrapper(httpContext);
        //    var routeData = new RouteData();
        //    var requestContext = new RequestContext(httpContextBase, routeData);

        //    return new UrlHelper(requestContext);
        //}

    }
}